package indi.gao.springAopTest.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2020$</p>
 * <p>Company: Tope</p>
 * <P>Created Date :2020$-05$-08$</P>
 * <P>@version 1.0</P>
 */
@Service
public class OPService {
    // 这里进行标注为异步任务，在执行此方法的时候，会单独开启线程来执行(并指定线程池的名字)
    @Async("taskExecutor1")
    public  Future<Integer>  findUser(CountDownLatch countDownLatch) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // Artificial delay of 3s for demonstration purposes
        System.out.println(Thread.currentThread());
//        countDownLatch.countDown();
        return new AsyncResult<Integer>(1);
    }
}
